﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Reticulum
{
    public partial class ForgetPWD : Form
    {
        public ForgetPWD()
        {
            InitializeComponent();
        }

        private void ForgetPWD_Load(object sender, EventArgs e)
        {

        }
        public static string UserAccount = "", UserPhone = "", UserPwd = "";
        private void button1_Click(object sender, EventArgs e)
        {
            
            if (textBox1.Text=="")
            {
                MessageBox.Show("账号不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("手机号不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (textBox1.Text == ""&& textBox2.Text == "")
            {
                MessageBox.Show("账号和手机号不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (textBox1.Text != "" && textBox2.Text != "")
            {
                string sql = string.Format("select UserAccount,UserPhone,UserPwd from Users");
                while (DBHelps.Select(sql).Read())
                {
                    if (textBox1.Text == DBHelps.Select(sql)["UserAccount"].ToString())
                    {
                        UserAccount = DBHelps.Select(sql)["UserAccount"].ToString();
                    }
                    if (textBox2.Text == DBHelps.Select(sql)["UserPhone"].ToString())
                    {
                        UserPhone = DBHelps.Select(sql)["UserPhone"].ToString();
                    }
                    if (textBox1.Text == DBHelps.Select(sql)["UserAccount"].ToString() 
                        && textBox2.Text == DBHelps.Select(sql)["UserPhone"].ToString())
                    {
                        UserPwd = DBHelps.Select(sql)["UserPwd"].ToString();
                    }
                }
                DBHelps.Select(sql).Close();
                DBHelps.reader = null;

                if (UserAccount==textBox1.Text&& UserPhone==textBox2.Text)
                {
                    DialogResult result = MessageBox.Show("你的密码是：" + UserPwd+ "\n您是否需要修改密码？", "密码找回成功！"
                        ,MessageBoxButtons.YesNo,MessageBoxIcon.Question);
                    if (result==DialogResult.Yes)
                    {
                        UpdataPWD updataPWD = new UpdataPWD();
                        updataPWD.Show();
                    }
                }
                else if(UserAccount != "" && UserPhone != textBox2.Text)
                {
                    MessageBox.Show("您的手机号输入错误,找回失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (UserAccount == "" && UserPhone == textBox2.Text)
                {
                    MessageBox.Show("您的账号输入错误,找回失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show("您的账号和手机号输入都不正确！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
    }
}
